package com.maplefire;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
@ExtendWith(SpringExtension.class)
public class SpringBootApplicationTests {

    @Autowired
    private MockMvc mockMvc;

    @Test
    public void test_applyOrder() throws Exception {

        mockMvc.perform(MockMvcRequestBuilders
                .post("/test/applyOrder")
                .contentType(MediaType.APPLICATION_JSON)
                .content("{\"source\":\"collect\",\"operation\":\"applyOrder\",\"orderId\":\"123456\",\"status\":\"1\"}")
                .accept(MediaType.APPLICATION_JSON))
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andExpect(MockMvcResultMatchers.content().string("success"));
    }

    @Test
    public void test_boundOrder() throws Exception {

        mockMvc.perform(MockMvcRequestBuilders
                .post("/test/boundOrder")
                .contentType(MediaType.APPLICATION_JSON)
                .content("{\"source\":\"collect\",\"operation\":\"orderBound\",\"orderId\":\"123456\",\"status\":\"2\"}")
                .accept(MediaType.APPLICATION_JSON))
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andExpect(MockMvcResultMatchers.content().string("success"));
    }

    @Test
    public void test_updateMailNo() throws Exception {

        mockMvc.perform(MockMvcRequestBuilders
                .post("/test/updateMailNo")
                .contentType(MediaType.APPLICATION_JSON)
                .content("{\"source\":\"smile\",\"operation\":\"updateMailNo\",\"orderId\":\"123456\",\"courierCode\":\"11111\",\"branchCode\":\"123\"}")
                .accept(MediaType.APPLICATION_JSON))
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andExpect(MockMvcResultMatchers.content().string("success"));
    }

}